package com.qf.controller.login;

import com.google.protobuf.StringValue;
import com.qf.controller.BaseController;
import com.qf.pojo.StuInfo;
import com.qf.service.LoginService;
import com.qf.service.impl.LoginServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 沐辰
 * @version v1.0
 * @description:
 * @project _4.30_Exam_two
 * @Date 2024/4/30 9:26
 * @company qf
 */
@WebServlet(name = "LoginController",urlPatterns = "/login")
public class LoginController extends BaseController {

    private LoginService loginService = new LoginServiceImpl();

    /**
     * 登录功能处理
     * @param request
     * @param response
     * @return
     */
    public String login(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //调用业务层
        StuInfo stuInfo = loginService.login(username, password);
        if (stuInfo != null) {
            request.getSession().setAttribute("name",stuInfo.getStuName());
            request.getSession().setAttribute("id",stuInfo.getId());
            if (stuInfo.getStatus()==0) {
                return "forward:/success.jsp";
            } else {
                return "forward:/successAdmin.jsp";
            }

        }
        request.getSession().setAttribute("errl","用户名或密码错误");
        return "forward:/index.jsp";
    }
}
